package sample.badgeview.starry.matrixxun.com.materialbadgetextview;

import com.matrixxun.starry.badgetextview.MenuItemBadge;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbility extends Ability implements Component.ClickedListener {
    MenuItemBadge menuShop;
    MenuItemBadge menuMessage;
    MenuItemBadge menuNotification;
    MenuItemBadge menuFeature;
    int index = 1;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_main);
        menuShop = (MenuItemBadge) findComponentById(ResourceTable.Id_menu_shopcart);
        menuShop.setBadgeCount("new");
        menuShop.setClickedListener(this);
        menuNotification = (MenuItemBadge) findComponentById(ResourceTable.Id_menu_notification);
        menuNotification.setBadgeCount(5);
        menuNotification.setClickedListener(this);
        menuMessage = (MenuItemBadge) findComponentById(ResourceTable.Id_menu_message);
        menuMessage.setBadgeCount(999);
        menuMessage.setClickedListener(this);
        menuFeature = (MenuItemBadge) findComponentById(ResourceTable.Id_menu_feature);
        menuFeature.setBadgeCount("");
        menuFeature.setClickedListener(this);
    }

    boolean isMessage = false;

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_menu_shopcart:
                new ToastDialog(this).setText("Shop Cart").show();
                break;
            case ResourceTable.Id_menu_notification:
                menuNotification.setHighLightMode();
                break;
            case ResourceTable.Id_menu_feature:
                menuFeature.setBadgeCount(index++);
                break;
            case ResourceTable.Id_menu_message:
                isMessage = !isMessage;
                if (isMessage) {
                    menuMessage.clearHighLightMode();
                } else {
                    menuMessage.setBadgeCount("999");
                }
                break;
        }
    }
}
